<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 求1*2*3...*n阶乘
        // 方法一：
        var a = 1;
        var index = 1;

        function fn(n) {
            index *= a;
            if (a == n) {
                console.log(index);
                return
            }
            a++;
            fn(n);
        }
        fn(4);
        // 方法二：
        function fun(n) {
            if (n === 1) {
                return 1;
            }
            return n * fun(n - 1);
        }
        console.log(fun(4));
    </script>
</body>

</html>